//
//  MPOSSManager.h
//

#import <Foundation/Foundation.h>
#import <AliyunOSSiOS/AliyunOSSiOS.h>

/*!
 Error domain used
 */
extern NSString * _Nullable const kMPOSSErrorDomain;

/**
 * @brief: MPOSSClientErrorCode error codes.
 */
typedef NS_ENUM(NSInteger, MPOSSClientErrorCode) {
    MPOSSClientErrorCodeNotKnown,//未知错误
    MPOSSClientErrorCodeInvalidArgument,//参数不可用
    MPOSSClientErrorCodeDataTooBig,//数据超大
    MPOSSClientErrorCodeNoAccessInfo,//授权信息不存在
};

typedef void (^MPOSSNetworkingUploadProgressBlock) (int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend);


@protocol MPAccessInfoProviderProtocol <NSObject>

-(void)updateAccessInfoWithSuccess:(void (^_Nonnull)(id _Nullable objc,BOOL isCache))success failure:(void (^_Nonnull)(NSError * _Nonnull error))failure;

@end



NS_ASSUME_NONNULL_BEGIN

@interface MPOSSManager : NSObject

/*!
 @property
 @abstract app标识符。
 */
@property (nonatomic, copy) NSString *clientId;

/*!
 @property
 @abstract 登录后获取的access_token，后续接口需要使用access_token计算校验签名。
 */
@property (nonatomic, copy) NSString *access_token;

/*!
 @property
 @abstract OSS服务的信息，包括stsToken，accessKeySecret，accessKeyId，expiration，dir，host，region，bucket。
 */
@property (nonatomic, strong) NSDictionary *access_info;

/*!
 @property
 @abstract 获取access_info的服务地址。
 */
@property (nonatomic, copy) NSString *authServerUrl;

/*!
 @property
 @abstract 单次上传最大字节数，默认100 * 1024 *1024。
 */
@property (nonatomic, assign) NSInteger maxUploadDataSize;

/*!
 @property
 @abstract 用于上传的OSSClient对象。
 */
@property (nonatomic, strong) OSSClient *defaultClient;

/*!
 @property
 @abstract 生成OSSClient的配置对象。
 */
@property (nonatomic, strong) OSSClientConfiguration *clientConfig;

/*!
 @property
 @abstract OSS服务授权提供对象。
 */
@property (nonatomic, strong) id <MPAccessInfoProviderProtocol>accessInfoProviderImp;


/*!
 @method
 @abstract 获取SDK版本号
 */
+ (NSString *)SDKVersion;

/*!
 @method
 @abstract 获取单例对象
 */
+ (instancetype)sharedManager;

/*!
 @method
 @abstract 更新OSS服务授权信息
 */
-(void)updateAccessInfoWithSuccess:(void (^)(id _Nullable))success failure:(void (^)(NSError * _Nonnull))failure;

/**
 upload file asynchronously
 
 @param data 待上传的数据data
 @param fileName  数据名称，不可为nil
 @param progressBlock progress block 子线程回调
 @param success success block，主线程回调，返回OSSPutObjectResult对象，使用方需要将json字符串转为NSDictionary，其中data字段为上传后的文件url。
 @param failure failure block 子线程回调
 */
- (void)asyncPutFileData:(NSData *)data fileName:(NSString *)fileName  progress:(MPOSSNetworkingUploadProgressBlock)progressBlock success:(void (^)(id _Nullable responseObjcet))success failure:(void (^)(NSError * _Nonnull))failure;

/**
 upload file asynchronously
 
 @param localFilePath local file's path
 @param fileName  如果为nil，则默认从本地文件路径截取名称和类型
 @param progressBlock progress block 子线程回调
 @param success success block，主线程回调，返回OSSPutObjectResult对象，使用方需要将json字符串转为NSDictionary，其中data字段为上传后的文件url。
 @param failure failure block 子线程回调
 */
- (void)asyncPutFlieWithFilePath:(NSString *)localFilePath fileName:(NSString *_Nullable)fileName progress:(MPOSSNetworkingUploadProgressBlock)progressBlock success:(void (^)(id _Nullable responseObjcet))success failure:(void (^)(NSError * _Nonnull error))failure;

@end

NS_ASSUME_NONNULL_END
